package cn.alcatraz.mq_05_tran;

import org.apache.rocketmq.client.producer.LocalTransactionState;
import org.apache.rocketmq.client.producer.TransactionListener;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageExt;

/**
* @Description: 事务监听
* @Author: Alcatraz
* @Version: 1.0
* @Date:  2022/7/26 21:14
*/

public class MyTranIistener implements TransactionListener {
    /**
     * 执行本地事务
     * @param message
     * @param o
     * @return
     */
    @Override
    public LocalTransactionState executeLocalTransaction(Message message, Object o) {
        System.out.println("执行业务，保存本地事务");
        // 返回事务提交成功状态
        return LocalTransactionState.COMMIT_MESSAGE;
    }

    /**
     * 检查本地事务
     * @param messageExt
     * @return
     */
    @Override
    public LocalTransactionState checkLocalTransaction(MessageExt messageExt) {
        System.out.println("检查本地事务，事务提交成功");
        // 返回事务提交成功状态
        return LocalTransactionState.COMMIT_MESSAGE;
    }
}
